package jp.eisbahn.mgapi.servlets;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;

import jp.eisbahn.mgapi.auth.AuthorizationCodeListener;

/**
 * This class has a basic operation for setting the listener.
 * @author Yoichiro Tanaka
 */
@SuppressWarnings("serial")
public class BasicAuthorizationCodeServlet extends AuthorizationCodeServlet {

    /*
     * (non-Javadoc)
     * @see javax.servlet.GenericServlet#init(javax.servlet.ServletConfig)
     */
    @Override
    public final void init(final ServletConfig config) throws ServletException {
        super.init(config);
        String className = config.getInitParameter("authorizationCodeListener");
        try {
            Class<?> clazz = Class.forName(className);
            AuthorizationCodeListener listener =
                (AuthorizationCodeListener) clazz.newInstance();
            setAuthorizationCodeListener(listener);
        } catch (ClassNotFoundException e) {
            throw new ServletException(e);
        } catch (InstantiationException e) {
            throw new ServletException(e);
        } catch (IllegalAccessException e) {
            throw new ServletException(e);
        }
    }

}
